/*
Access GPX data files.
- Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008,
- 2009, 2010 Robert Lipe, gpsbabel.org
+ Copyright (C) 2002-2013 Robert Lipe, gpsbabel.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <expat.h>
static XML_Parser psr;
#endif
-#include <QtCore/QXmlStreamWriter>
+#include "src/core/xmlstreamwriter.h"
#include <QtCore/QRegExp>
#include <QtCore/QDebug>
//#include <QtCore/QTextCodec>
static const char* input_fname;
static gbfile* ofd = NULL;
static QString ostring;
-static QXmlStreamWriter writer(&ostring);
+static gpsbabel::XmlStreamWriter writer(ostring);
static short_handle mkshort_handle;
static const char* link_url;
static char* link_text;
url_link* tail;
for (tail = (url_link*)&waypointp->url_next; tail; tail = tail->url_next) {
writer.writeStartElement("link");
- if(tail->url && tail->url[0]) {
writer.writeAttribute("href", tail->url);
- }
- if(tail->url_link_text && tail->url_link_text[0]) {
- writer.writeTextElement("text", tail->url_link_text);
- }
+ writer.writeOptionalTextElement("text", tail->url_link_text);
// FIXME This is to force empty links to not be self-closing. This is
// lame, but it's for compatibilty with our old writer to minimize thrash
// on the Qt transition.
return;
}
writer.writeTextElement("url", QString(urlbase) + QString(waypointp->url));
- if (waypointp->url_link_text && waypointp->url_link_text[0]) {
- writer.writeTextElement("urlname", QString(waypointp->url_link_text));
- }
+ writer.writeOptionalTextElement("urlname", QString(waypointp->url_link_text));
#endif
}
if (oname) {
writer.writeTextElement("name", oname);
}
- if (waypointp->description && waypointp->description[0]) {
- writer.writeTextElement("cmt", waypointp->description);
- }
+ writer.writeOptionalTextElement("cmt", waypointp->description);
if (waypointp->notes && waypointp->notes[0]) {
writer.writeTextElement("desc", waypointp->notes);
} else {
- if (waypointp->description && waypointp->description[0]) {
- writer.writeTextElement("desc", waypointp->description);
- }
+ writer.writeOptionalTextElement("desc", waypointp->description);
}
write_gpx_url(waypointp);
if (!waypointp->icon_descr.isNull()) {
}
#else
writer.writeStartElement("trk");
- if (rte->rte_name && rte->rte_name[0]) {
- writer.writeTextElement("name", rte->rte_name);
- }
- if (rte->rte_desc && rte->rte_desc[0]) {
- writer.writeTextElement("desc", rte->rte_desc);
- }
+ writer.writeOptionalTextElement("name", rte->rte_name);
+ writer.writeOptionalTextElement("desc", rte->rte_desc);
if (rte->rte_num) {
writer.writeTextElement("number", QString::number(rte->rte_num));
}
write_optional_xml_entity(ofd, " ", "name", rte->rte_name);
write_optional_xml_entity(ofd, " ", "desc", rte->rte_desc);
#else
- if (rte->rte_name && rte->rte_name[0]) {
- writer.writeTextElement("name", rte->rte_name);
- }
- if (rte->rte_desc && rte->rte_desc[0]) {
- writer.writeTextElement("desc", rte->rte_desc);
- }
+ writer.writeOptionalTextElement("name", rte->rte_name);
+ writer.writeOptionalTextElement("desc", rte->rte_desc);
#endif
if (rte->rte_num) {
#if OLDGPX
--- /dev/null
+/*
+ Copyright (C) 2013 Robert Lipe, gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+
+#include <QtCore/QXmlStreamWriter>
+
+// As this code began in C, we have several hundred places that write
+// c strings. Add a test that the string contains anything useful
+// before serializing an empty tag.
+
+namespace gpsbabel {
+
+class XmlStreamWriter : public QXmlStreamWriter {
+public:
+ XmlStreamWriter(QString& s) : QXmlStreamWriter(&s) {}
+
+ // Dont emit the attribute if there's nothing interesting in it.
+ void writeOptionalAttribute(QString tag, QString value) {
+ if (!value.isEmpty()) {
+ writeAttribute(tag, value);
+ }
+ }
+
+ // Dont emit the tag if there's nothing interesting in it.
+ void writeOptionalTextElement(QString tag, QString value) {
+ if (!value.isEmpty()) {
+ writeTextElement(tag, value);
+ }
+ }
+
+};
+
+}; // namespace gpsbabel